<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <!-- 满足有些用户在手机端访问的需要 -->

    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">

    <title>用户管理</title>
    <!-- 线上环境 -->
    <link rel="stylesheet" href="/static/css/dist/component-min.css">
    <link rel="stylesheet" href="/static/plugins/jbox/jbox-min.css">

    <!--vue-->
    <script src="/static/vue/vue.js"></script>
    <!--element ui-->
    <script src="/static/element/index.js"></script>
    <link rel="stylesheet" href="/static/element/index.css">
    <style>
        .el-table__empty-block {
            height: 0;
        }
    </style>

</head>
<body class="cp-bodybox">
<div id="app">
    <#include "/common/header-fg.html" />

    <div class="container">
        <div class="inner clearfix">
            <#include "/common/left-menu-fg.html" />

            <div class="content-right">
                <h1 class="content-right-title">商家管理</h1>
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span style="line-height: 36px;">筛选区</span>
                        <div style="float: right">
                            <el-button type="primary" @click.native.prevent="getList">查询</el-button>
                            <el-button type="primary" @click.native.prevent="clearSearch">清空查询条件</el-button>
                        </div>
                    </div>
                    <el-form :inline="true" ref="search" :model="search" label-width="80px">
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="名称搜索">
                                    <el-input v-model="search.name" placeholder="名称"></el-input>
                                </el-form-item>
                            </el-col>
                            <!--<el-col :span="12">-->
                                <!--<el-form-item label="性质">-->
                                    <!--<el-select v-model="search.character" placeholder="请选择性质">-->
                                        <!--<el-option-->
                                                <!--v-for="item in natureList"-->
                                                <!--:label="item.name"-->
                                                <!--:value="item.value">-->
                                        <!--</el-option>-->
                                    <!--</el-select>-->
                                <!--</el-form-item>-->
                            <!--</el-col>-->
                            <el-col :span="12">
                                <el-form-item label="地址">
                                    <el-cascader
                                            v-model="search.city"
                                            v-loading="addressLoading"
                                            :options="addressList"
                                            @active-item-change="handleItemChange"
                                    ></el-cascader>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row>
                            <el-col :span="12">
                                <el-form-item label="状态">
                                    <el-select v-model="search.status" placeholder="请选择状态">
                                        <el-option
                                                v-for="item in stateList"
                                                :label="item.name"
                                                :value="item.value">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="销售额">
                                    <el-input v-model="search.saleAmountLow" style="width: 200px;"></el-input>&nbsp;元至&nbsp;
                                    <el-input v-model="search.saleAmountHigh" style="width: 200px;"></el-input>&nbsp;元
                                </el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                </el-card>
                <yiqi-examine ref="examineDialog" :examine-dialog="examineDialog" :readonly="readonly"
                              :checked-list="checkedList" :result="result" :desc="desc"
                              :type-id="typeId" :save-callback="saveCallback" :cancel-callback="cancelCallback"></yiqi-examine>
                <el-card class="box-card" style="margin-top: 10px">
                    <div slot="header" class="clearfix">
                        <span style="line-height: 36px;">商家信息列表</span>
                        <el-button type="primary" v-if="isPermission('org:add', user.permissions)" style="float: right;" @click.native="forwardAdd">添加</el-button>
                    </div>
                    <el-table
                            :data="orgList"
                            border
                            style="width: 100%">
                        <el-table-column
                                inline-template
                                label="序号"
                                width="80">
                            <div>{{ $index+pageSize*(currentPage-1)+1 }}</div>
                        </el-table-column>
                        <el-table-column
                                prop="name"
                                label="商家名称"
                                width="180">
                        </el-table-column>
                        <el-table-column
                                prop="parentName"
                                label="上级商家">
                        </el-table-column>
                        <el-table-column
                                inline-template
                                show-overflow-tooltip
                                label="地区">
                            <div>{{row.provinceName !== undefined ? row.provinceName : ""}}{{row.cityName !== undefined ? row.cityName : ""}}{{row.countyName !== undefined ? row.countyName : ""}}</div>
                        </el-table-column>
                        <!--<el-table-column-->
                                <!--prop="characterName"-->
                                <!--label="性质">-->
                        <!--</el-table-column>-->
                        <el-table-column
                                align="center"
                                prop="statusName"
                                label="状态">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                prop="enable"
                                :formatter="formatterStatus"
                                label="是否禁用">
                        </el-table-column>
                        <el-table-column
                                prop="staffNumber"
                                label="规模(人)">
                        </el-table-column>
                        <el-table-column
                                prop="saleAmount"
                                label="销售额">
                        </el-table-column>
                        <el-table-column
                                prop="establishTime"
                                :formatter="formatterTime"
                                label="创立时间">
                        </el-table-column>
                        <el-table-column
                                align="center"
                                label="操作"
                                inline-template>
                            <div style="margin-left: -10px">
                                <el-dropdown>
                                    <el-button size="small" type="primary">
                                        操作<i class="el-icon-caret-bottom el-icon--right"></i>
                                    </el-button>
                                    <el-dropdown-menu slot="dropdown" align="center">
                                        <el-dropdown-item v-if="isPermission('user:add', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="edit(row.id, true)">添加账号</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('org:enable', user.permissions)">
                                            <el-button size="mini" type="primary" v-if="row.enable !== 0" @click.native="enable(row)">禁用</el-button>
                                            <el-button size="mini" type="primary" v-else @click.native="enable(row)">启用</el-button>
                                        </el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('org:view', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="detail(row.id, false)">详情</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('org:check', user.permissions)"><el-button size="mini" type="primary" v-if="row.status === 0" @click.native.prevent="examine(row)">审核</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('org:edit', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="edit(row.id, false)">编辑</el-button></el-dropdown-item>
                                        <el-dropdown-item v-if="isPermission('org:delete', user.permissions)"><el-button size="mini" type="primary" @click.native.prevent="deleteOrg(row.id)">删除</el-button></el-dropdown-item>
                                    </el-dropdown-menu>
                                </el-dropdown>
                            </div>
                        </el-table-column>
                    </el-table>
                    <el-pagination
                            @current-change="handleCurrentPageChange"
                            :current-page="currentPage"
                            :page-size="pageSize"
                            layout="total, prev, pager, next"
                            :total="totalCount">
                    </el-pagination>
                </el-card>

            </div>
            <!-- end content-right -->

            <a href="javascript:;" class="btn-leftMenuFold" id="j-btn-leftMenuFold"></a>
        </div>
    </div>
    <!-- end container -->

    <!--gonggao-->

    <!--tip-->
    <div class="footer">© 2017 , Inc. All rights reserved.</div>
    <!-- end footer -->
    <div class="fixedBar" style="right: -78px;">
        <ul>
            <template v-for="(item, index) in leftMenuList">
                <li v-if="index==0" :class="'shopManager' + index + ' cur'"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
                <li v-else :class="'shopManager' + index"><a href="javascript:;" :data-target="'#shop_' + index">{{item.groupName}}</a></li>
            </template>
        </ul>
        <a href="javascript:;" class="fixedBar-btn" id="j-fixedBar-btn"></a>
    </div>\
    <a href="#" id="j-gotop" class="gotop" title="回到顶部" style="left: 1920.59px;"></a>

</div>
<script src="/static/js/dist/lib-min.js"></script>
<script src="/static/js/dist/list.js"></script>
<script src="/static/js/dist/component-min.js"></script>
<script src="/static/js/common.js"></script>

<!-- 引入api -->
<script src="/static/js/api.js"></script>
<script>
    new Vue({
        el: '#app',
        data: function(){
            return {
                user: ${(user)!'null'},
                examineDialog: false,
                addressLoading: false,
                addressList: [],
                headerNavList: list.headerNavList,
                natureList: [],
                stateList: [],
                typeId: 5,
                readonly: false,
                result: 1,
                checkedList: [],
                desc: '',
                examineId: '',
                accountNavList: list.accountNavList,
                leftMenuList: list.menu,
                search: {
                    name: '',
                    city: [],
                    status: '',
                    saleAmountLow: '',
                    saleAmountHigh: '',
                    character: ''
                },
                activeNames: ['1', '2'],
                orgList: [],
                currentPage: list.currentPage,
                pageSize: list.pageSize,
                totalCount: 100
            }
        },
        methods: {
            handleCurrentPageChange(val) {
                this.currentPage = val;
                this.getList();
            },
            forwardAdd () {
                window.location.href = '/org/add'
            },
            detail (id, addAccountFlag) {
                window.location.href = '/org/detail?orgId=' + id + "&addAccountFlag=" + addAccountFlag;
            },
            edit (id, addAccountFlag) {
                window.location.href = '/org/edit?orgId=' + id + "&addAccountFlag=" + addAccountFlag;
            },
            handleItemChange (val) {
                if (val.length === 1) {
                    this.getAddress(parseInt(val[0]), "city");
                } else if (val.length === 2){
                    this.getAddress(val, "area");
                }
            },
            getAddress (code, index) {
                let that = this;
                let cityCode = '';
                if (index === "area") {
                    cityCode = code[1];
                } else {
                    cityCode = code;
                }
                this.addressLoading = true;
                this.http("/city/list", {cityCode: cityCode}, function (res) {
                    if (res.status === 200) {
                        if (index === "province") {
                            that.addressList = res.data.list;
                            that.getProvince = true;
                        } else if (index === "city") {
                            that.addressList.forEach(function (item) {
                                if (item.value === (code+'')) {
                                    item.children = res.data.list;
                                }
                            })
                            that.getCity = true;
                        } else if (index === "area") {
                            for(let i = 0; i < that.addressList.length; i++) {
                                if (that.addressList[i].value === code[0]) {
                                    let data = that.addressList[i].children;
                                    for (let j = 0; j < data.length; j++) {
                                        if (data[j].value === code[1]) {
                                            data[j].children = res.data.list;
                                            break;
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                        that.addressLoading = false;
                    } else {
                        that.addressLoading = false;
                        that.$alert(res.errMsg, '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    that.addressLoading = false;
                    that.$alert('获取地址数据失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            examine (row) {
                this.examineId = row.id;
                this.readonly = parseInt(row.status) !== 0 ? true : false;
                this.result = parseInt(row.status) === -1 ? 0 : 1;
                if (this.readonly) {
                    let that = this;
                    let obj = {
                        contentId: row.id,
                        contentType: this.typeId
                    }
                    this.http("/check/getCheckInfo", obj, function (res) {
                        if (res.status === 200) {
                            if (res.data.selectCheck !== undefined) {
                                that.desc = res.data.selectCheck.checkDesc;
                            }
                            that.examineDialog = true;
                        } else {
                            that.$alert('服务器错误','提示',{
                                confirmButtonText:'确定',
                            })
                        }
                    }, function (res) {
                        that.$alert('服务器错误','提示',{
                            confirmButtonText:'确定',
                        })
                    })
                } else {
                    this.examineDialog = true;
                }
            },
            clearSearch () {
                this.search = {
                    name: '',
                    city: [],
                    status: '',
                    saleAmountLow: '',
                    saleAmountHigh: '',
                    character: ''
                };
                this.getList();
            },
            getCharacter () {
                let that = this;
                this.$get("/dictionary/list/SEC_ORG_CHARACTER", {}, function (res) {
                    if (res.status === 100) {
                        that.natureList = res.returnValue;
                    } else {
                        that.$alert('服务器错误','提示',{
                            confirmButtonText:'确定',
                        })
                    }
                }, function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            getStatus () {
                let that = this;
                this.$get("/dictionary/list/SEC_ORG_STATUS", {}, function (res) {
                    if (res.status === 100) {
                        that.stateList = res.returnValue;
                    } else {
                        that.$alert('服务器错误','提示',{
                            confirmButtonText:'确定',
                        })
                    }
                }, function (res) {
                    that.$alert('服务器错误','提示',{
                        confirmButtonText:'确定',
                    })
                })
            },
            deleteOrg (id) {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true});
                this.http("/org/delete", {id: id}, function (res) {
                    if (res.status === 200) {
                        that.getList();
                        loading.close();
                        that.$alert('删除成功', '提示', {
                            confirmButtonText: '确定',
                        });
                    } else {
                        loading.close();
                        that.$alert('删除失败', '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('删除失败', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            enable (row) {
                let that = this;
                let url = "";
                let loading = this.$loading({fullscreen: true, lock: true});
                if (row.enable === 0) {
                    url = "/org/enable";
                } else {
                    url = "/org/disable";
                }
                this.http(url, {id: row.id}, function (res) {
                    if (res.status === 200) {
                        row.enable = row.enable === 1 ? 0 : 1;
                        loading.close();
                    } else {
                        loading.close();
                        that.$alert('服务器错误', '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            },
            formatterStatus (row, column) {
                if (row.enable === 0) {
                    return '禁用';
                } else {
                    return '启用';
                }
            },
            formatterTime (row, column) {
                if (row.establishTime !== undefined && (row.establishTime + "").length >= 10) {
                    return (row.establishTime + "").substring(0, 10);
                } else {
                    return row.establishTime;
                }
            },
            saveCallback () {
                let isValid = true;
                let that = this;
                this.result = this.$refs.examineDialog.examineForm.result;
                this.desc = this.$refs.examineDialog.examineForm.desc;
                this.checkedList = this.$refs.examineDialog.checkTag;
                this.$refs.examineDialog.$refs.examineForm.validate(function (valid) {
                    if (!valid) {
                        isValid = false;
                    }
                })
                if (isValid) {
                    let desc = "";
                    if (this.checkedList[0] === 999) {
                        desc = this.desc;
                    } else {
                        desc = this.checkedList.join(",");
                    }
                    let obj = {
                        contentId: this.examineId,
                        checkResult: this.result,
                        checkDesc: desc
                    }
                    let loading = this.$loading({fullscreen: true, lock: true});
                    this.http("/org/check", obj, function (res) {
                        if (res.status === 200) {
                            that.getList();
                            that.examineDialog = false;
                            loading.close();
                        } else {
                            loading.close();
                            that.$alert('服务器错误', '提示', {
                                confirmButtonText: '确定',
                            });
                        }
                    }, function (res) {
                        loading.close();
                        that.$alert('服务器错误', '提示', {
                            confirmButtonText: '确定',
                        });
                    })
                } else {
                    this.$message.error('请完善信息');
                }
            },
            cancelCallback () {
                this.result = 1;
                this.checkedList = [];
                this.desc = "";
                this.examineDialog = false;
            },
            getList () {
                let that = this;
                let loading = this.$loading({fullscreen: true, lock: true, text: '加载中'});
                let obj = {
                    character: this.search.character,
                    city: this.search.city.length !== 0 ? this.search.city[this.search.city.length - 1] : "",
                    status: this.search.status,
                    saleAmountLow: this.search.saleAmountLow,
                    saleAmountHigh: this.search.saleAmountHigh,
                    name: this.search.name,
                    currentPage: this.currentPage,
                    pageSize: this.pageSize
                }
                this.http("/org/list", obj, function (res) {
                    if (res.status === 200) {
                        that.orgList = res.data.list;
                        that.totalCount = res.data.total;
                        loading.close();
                    } else {
                        loading.close();
                        that.$alert('服务器错误', '提示', {
                            confirmButtonText: '确定',
                        });
                    }
                }, function (res) {
                    loading.close();
                    that.$alert('服务器错误', '提示', {
                        confirmButtonText: '确定',
                    });
                })
            }
        },
        mounted: function () {
//            this.getCharacter();
            this.getAddress(0, "province");
            this.getStatus();
            this.getList();
        }
    })
</script>

<!-- 20170105 --></body>
</html>